package kr.co.handysoft.project.smartPolice.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

public class ImageViewDialog extends Dialog {

	protected Object result;
	protected Shell shlImageview;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public ImageViewDialog(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shlImageview.open();
		shlImageview.layout();
		Display display = getParent().getDisplay();
		
        Rectangle shellBounds = getParent().getBounds();
        Point dialogSize = shlImageview.getSize();

        shlImageview.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
		          shellBounds.y + (shellBounds.height - dialogSize.y) / 2);

		
		while (!shlImageview.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlImageview = new Shell(getParent(), getStyle());
		shlImageview.setSize(972, 514);
		shlImageview.setText("Remote Image View");
		
		CLabel lblNewLabel = new CLabel(shlImageview, SWT.NONE);
		lblNewLabel.setImage(SWTResourceManager.getImage(ImageViewDialog.class, "/sampleImage/20130219132701_008_01_\uCDA9\uB0A880\uC5441587.jpg"));
		lblNewLabel.setBounds(0, 0, 966, 486);
		lblNewLabel.setText("");

	}

}
